package com.byx.imserverutil.entity;

import com.byx.imserverutil.protobuf.ChatMessageProtobuf;

/**
 * ImMessage
 * 消息实体类，可转换成protobuf传输
 * @author Superb
 * @date 2021/2/9 12:55
 */
public class ImMessage {
    private String id;
    private int type;
    private int contentType;
    private String senderId;
    private String recipientId;
    private long timestamp;
    private int status;
    private String content;


    public String getId() {
        return id;
    }

    public int getType() {
        return type;
    }

    public int getContentType() {
        return contentType;
    }

    public String getSenderId() {
        return senderId;
    }

    public void setSenderId(String senderId) {
        this.senderId = senderId;
    }

    public String getRecipientId() {
        return recipientId;
    }

    public void setRecipientId(String recipientId) {
        this.recipientId = recipientId;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public int getStatus() {
        return status;
    }

    public String getContent() {
        return content;
    }

    public static Builder newBuilder(){
        return new Builder();
    }

    public ChatMessageProtobuf.Msg convert(){
        return ChatMessageProtobuf.Msg.newBuilder()
                .setMessageId(this.id)
                .setFromId(this.senderId)
                .setToId(this.recipientId)
                .setContent(this.content)
                .setMessageType(this.type)
                .setMessageContentType(this.contentType)
                .setTimestamp(this.timestamp)
                .setStatusReport(this.status)
                .build();
    }

    public static final class Builder {
        private String id;
        private int type;
        private int contentType;
        private String senderId;
        private String recipientId;
        private long timestamp;
        private int status;
        private String content;

        private Builder() {
        }

        public static Builder newBuilder() {
            return new Builder();
        }

        public Builder setId(String id) {
            this.id = id;
            return this;
        }

        public Builder setType(int type) {
            this.type = type;
            return this;
        }

        public Builder setContentType(int contentType) {
            this.contentType = contentType;
            return this;
        }

        public Builder setSenderId(String senderId) {
            this.senderId = senderId;
            return this;
        }

        public Builder setRecipientId(String recipientId) {
            this.recipientId = recipientId;
            return this;
        }

        public Builder setTimestamp(long timestamp) {
            this.timestamp = timestamp;
            return this;
        }

        public Builder setStatus(int status) {
            this.status = status;
            return this;
        }

        public Builder setContent(String content) {
            this.content = content;
            return this;
        }

        public ImMessage build() {
            ImMessage imMessage = new ImMessage();
            imMessage.setSenderId(senderId);
            imMessage.setRecipientId(recipientId);
            imMessage.contentType = this.contentType;
            imMessage.id = this.id;
            imMessage.timestamp = this.timestamp;
            imMessage.type = this.type;
            imMessage.status = this.status;
            imMessage.content = this.content;
            return imMessage;
        }
    }
}
